
%% Parameters

eval(['dynare ', model_name, '.mod noclearall nowarn']) ;

%% Extract variable details from Dynare output

n_ = M_.endo_nbr ; % Number of endogenous variables
l_ = M_.exo_nbr ;  % Number of exogenous variables
n_ = n_+1 ;        % Constant

SET.variable.n_ = n_ ; 
SET.variable.l_ = l_ ; 
SET.nparam      = M_.param_nbr ;

var_names   = cellstr(M_.endo_names) ;
param_names = cellstr(M_.param_names) ;
exo_var_names = cellstr(M_.exo_names) ;

for ii=1:n_-1
    eval(['SET.variable.',var_names{ii},'=',int2str(ii),';']) ;
end

for ii=1:l_
    eval(['SET.variable.shock.',exo_var_names{ii},'=',int2str(ii),';']) ;
end

for ii=1:M_.param_nbr
    eval(['SET.param_names.',param_names{ii},'=',int2str(ii),';']) ;
end

SET.param_names_num = SET.param_names ; 

v_ = SET.variable; 
p_ = SET.param_names; 

%% Tidy up

eval(['delete ' model_name '*.m']);
eval(['delete ' model_name '*.mat']);
eval(['delete ' model_name '*.swp']);
eval(['delete ' model_name '*.log']);
eval(['delete ' model_name '*.eps']);
eval(['delete ' model_name '*.pdf']);
eval(['delete ' model_name '*.fig']);
eval(['delete ' model_name '*.jnl']);
eval(['delete ' model_name '*.tex']);
eval(['rmdir +' model_name ' s']);
eval(['rmdir ' model_name ' s']);
